#ifndef _CCALMANAGER_H_
#define _CCALMANAGER_H_

#include "auto.h"

#include "ccalendar.h"

#include <buola/utility/usignal.h>

namespace buola { namespace bcal {

class CCalManager
{
public:
    CCalManager();
    ~CCalManager();

private:
    void InitDB();
    void PrepareQueries();

public:
    CCalendar *NewLocalCalendar(const std::wstring &pName);
    CCalendar *OpenFileCalendar(const io::CURI &pURL);

    const std::vector<CCalendar*> &GetCalendars()   {   return mCalendars;  }

    CCalendar *GetCurrent() {   return mCurrent;    }

private:
    CCalendar *AddCalendar(int pType,int pID);

    img::CColor GetStockColor();

private:
    CDatabase mDB;

public:
    USignal<void(CCalendar*)> sCalendarAdded;

    struct
    {
        CDBQuery mInsertCalendar;
        CDBQuery mInsertEvent;
        CDBQuery mGetEventsBetween;
        CDBQuery mGetCalendars;
        CDBQuery mGetCalendar;
    } mQueries;

    std::vector<CCalendar*> mCalendars;

    std::vector<img::CColor> mStockColors;

    CCalendar *mCurrent;
};

/*namespace buola*/ } /*namespace bcal*/ }

#endif
